package cuong.ptit.androidvn.thread;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import cuong.ptit.andoridvn.R;
import cuong.ptit.androidvn.helper.JSONParser;

/*
 * @author LeCuong 
 * @version 1.0
 */

public class ListThread extends ListActivity {

	private ProgressDialog pDialog;
	private String note_id;

	JSONParser jsonParser = new JSONParser();

	// list array to list thread
	ArrayList<HashMap<String, String>> threadList;

	// get json
	private static final String url_thread = "http://android.vn/api.php?action=getthreads&hash=d8e8fca2dc0f896fd7cb4cb0031ba249";

	// item thread

	private static final String TAG_TITLE = "title";
	private static final String TAG_VIEW = "view_count";
	private static final String TAG_REPLY = "reply_cout";
	private static final String TAG_USERPOST = "user_post";
	private static final String TAG_POST_DATE = "post_date";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_thread);

		Intent i = getIntent();
		note_id = i.getStringExtra("node_id");

		threadList = new ArrayList<HashMap<String, String>>();
		
		//load thread
		new LoadThread().execute();

	}

	class LoadThread extends AsyncTask<String, String, String> {

		// show progress dialog-----------------
		@Override
		protected void onPreExecute() {
			super.onPreExecute();

			pDialog = new ProgressDialog(ListThread.this);
			pDialog.setMessage("Loading thread.......");
			pDialog.setIndeterminate(false);
			pDialog.setCancelable(false);
			//pDialog.show();
		}

		// json--------------------------
		@Override
		protected String doInBackground(String... agrs) {

			List<NameValuePair> parmas = new ArrayList<NameValuePair>();

			// post id thread as get pareameter
			parmas.add(new BasicNameValuePair("node_id", note_id));

			// get JSON string from URL
			String json = jsonParser.makeHttpRequest(url_thread, "GET", parmas);
			Log.d("thread", json+ "id thread="+note_id);
			return null;
		}

		// upload list thread----------------
		@Override
		protected void onPostExecute(String result) {
			// TODO Auto-generated method stub
			super.onPostExecute(result);
		}

	}
}
